<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Relations\CommonTrait;

/**
 *
 * @author Joker
 * `sender_uid` int(11) NOT NULL COMMENT '发送者ID',
	`sender_unread` mediumint(6) NOT NULL DEFAULT 0 COMMENT '发送者未读',
	`recipient_uid` int(11) NOT NULL COMMENT '接受者ID',
	`recipient_unread` mediumint(6) NOT NULL DEFAULT 0 COMMENT '接受者未读',
	`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
	`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
	`sender_count` int(11) NOT NULL DEFAULT 0 COMMENT '发送者显示对话条数',
	`recipient_count` int(11) NOT NULL DEFAULT 0 COMMENT '接受者显示对话条数',
 */
class InboxDialog extends Model
{
    use CommonTrait;
    protected $table="inbox_dialog";
    
    protected $primaryKey = 'id';
    
    protected $fillable = ['id','sender_uid','sender_unread','recipient_uid','recipient_unread','sender_count','recipient_count'];

    /**
     * 一对多获取 具体消息信息
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function inboxes()
    {
        return $this->hasMany('App\Models\Inbox','dialog_id','id');
    }
    
    public function sender()
    {
        return $this->hasOne('App\User','id','sender_uid');
    }
    
    public function recipient()
    {
        return $this->hasOne('App\User','id','recipient_uid');
    }
    
}